//
//  CurrencyCalc.m
//  BrcbBank
//
//  Created by nxjbill001 on 11-11-1.
//  Copyright 2011 深圳市移付宝科技有限公司. All rights reserved.
//

#import "WebViewController.h"


@implementation WebViewController
@synthesize webView,url;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
 // Custom initialization.
 }
 return self;
 }
 */

// load the view nib and initialize the pageNumber ivar
- (id)initWithHttpUrl:(NSString*)urlHttp
{
    if (self = [self initWithNibName:@"WebViewController" bundle:nil])
    {

		NSString *strAbsPath= [NSString stringWithFormat:@"encodeURI('%@')",urlHttp];
		self.url = strAbsPath;
		
    }
    return self;
}

// load the view nib and initialize the pageNumber ivar
- (id)initWithUrl:(NSString*)urlLocal
{
    if (self = [self initWithNibName:@"WebViewController" bundle:nil])
    {

		NSString *filePathOfIndex = [[NSBundle mainBundle] pathForResource:urlLocal ofType:nil];
		NSString *strAbsPath= [NSString stringWithFormat:@"encodeURI('file:///%@')",filePathOfIndex];
		self.url = strAbsPath;
    }
    return self;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	//self.navigationItem.title=@"外汇计算器";
	[self setNavShowDefaultLeft:kNavTitleTextStyle titleImageName:nil titleText:@"理财工具"];
	
NSLog(@"%@",self.url);
	
	self.url  = [webView stringByEvaluatingJavaScriptFromString:self.url];
	NSLog(@"%@",self.url);
	[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
	
}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations.
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
	self.webView = nil;
	self.url = nil;
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[webView stopLoading];
	webView.delegate = nil;
	[webView release];
	[url release];
	[super dealloc];
}


//+ (UIViewController *) createTabController{
//	CurrencyCalc *uiCtrl = [[[CurrencyCalc alloc] initWithNibName:@"CurrencyCalc" bundle:nil]autorelease];
//	UIImage *img = [UIImage imageNamed:@"tab_cal.png"];
//	[uiCtrl.tabBarItem initWithTitle:@"理财计算器" image:img tag:0];
//	return uiCtrl;
//}

#pragma mark -
#pragma mark UIViewController delegate methods

- (void)viewWillAppear:(BOOL)animated
{
	self.webView.delegate = self;	// setup the delegate as the web view is shown
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.webView stopLoading];	// in case the web view is still loading its content
	self.webView.delegate = nil;	// disconnect the delegate as the webview is hidden
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	// we support rotation in this view controller
	return YES;
}



#pragma mark -
#pragma mark UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView
{
	// starting the load, show the activity indicator in the status bar
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
	// finished loading, hide the activity indicator in the status bar
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
	// load error, hide the activity indicator in the status bar
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
	
	// report the error inside the webview
	NSString* errorString = [NSString stringWithFormat:
							 @"<html><center><font size=+5 color='red'>An error occurred:<br>%@</font></center></html>",
							 error.localizedDescription];
	[self.webView loadHTMLString:errorString baseURL:nil];
}


@end
